package chen.web.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;

import chen.web.forum.tag.Tag;
import chen.web.forum.tag.TagManager;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/test.xml"})
public class TagManagerTesting {

	@Autowired
	TagManager tm;

	@Test
	public void testAddTag(){
		Tag tag = new Tag("hello");
		tm.addTag(tag);
	}

	@Test
	public void testGetTag(){
		Tag tag = tm.getTag("hello");
		Assert.notNull(tag);
		Assert.isTrue("hello".equals(tag.getName()));
		tag = tm.getTag(tag.getId());
		Assert.notNull(tag);
		Assert.isTrue("hello".equals(tag.getName()));
	}
	
	@Test
	public void testModify(){
		Tag tag = tm.getTag("hello");
		tag.setName("hi");
		tm.modifyTag(tag);
		tag = tm.getTag(tag.getId());
		Assert.isTrue("hi".equals(tag.getName()));
		tag.setName("hello");
		tm.modifyTag(tag);
	}

	@Test
	public void testDeleteTag(){
		Tag tag = tm.getTag("hello");
		tm.deleteTag(tag);
		tag = tm.getTag("hello");
		Assert.isNull(tag);
	}
}
